package nine;

import static util.Print.print;

/**
 * Created by ab on 2016/11/3.
 * 工厂模式
 */
interface Service{
    void method1();
    void method2();
}
interface ServiceFactory{
    Service getService();
}
class Implementation1 implements Service{

    @Override
    public void method1() {
        print("Implementation1 method1");
    }

    @Override
    public void method2() {
        print("Implementation1 method2");
    }
}

class Implementtation1Factory implements ServiceFactory{
    public Service getService(){
        return new Implementation1();
    }
}

class Implementation2 implements Service{

    @Override
    public void method1() {
        print("Implementation2 method1");
    }

    @Override
    public void method2() {
        print("Implementation2 method2");
    }
}

class Implementtation2Factory implements ServiceFactory{
    public Service getService(){
        return new Implementation2();
    }
}
public class lesson4 {
    public static void serviceConsumer(ServiceFactory fact){
        Service s =fact.getService();
        s.method1();
        s.method2();
    }
    public static void main(String[] args){
        serviceConsumer(new Implementtation1Factory());
        serviceConsumer(new Implementtation2Factory());
    }
}
